b = input()
if int(b) > 999 and int(b) < 10000:
    s1 = b[0]
    s2 = b[1]
    s3 = b[2]
    s4 = b[3]
    n = [int(s1),
         int(s2),
         int(s3),
         int(s4),
         int(s1+s2),
         int(s2+s3),
         int(s3+s4),
         int(s1+s2+s3),
         int(s2+s3+s4),
         int(s1+s2+s3+s4)]
    q = 0
    v = []
    for u in n:
        q = 0
        for m in range(2, u - 1):
            if u % m == 0:
                q = 1
        if q == 0:
            v.append(u)
    if len(v) > 0:
        print(max(v))
    else:
        print(0)
else:
    print(0)
